package com.gupao.javavip.netty.push.client;

import com.gupao.javavip.netty.push.api.MsgType;
import com.gupao.javavip.netty.push.client.processor.handler.PushMsgRequestClientHandler;
import com.gupao.javavip.netty.push.client.processor.handler.PushMsgResponseClientHandler;
import com.gupao.javavip.netty.push.protocol.AbstractPushClientChannelInitializer;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import lombok.extern.apachecommons.CommonsLog;

@CommonsLog
public class PushMsgClientBase extends AbstractPushClient {
    private MsgType msgType;

    public PushMsgClientBase(String host, int port, MsgType msgType) {
        super(host, port);
        this.msgType = msgType;
    }

    @Override
    protected ChannelInitializer<SocketChannel> buildHandler() {
        return new AbstractPushClientChannelInitializer() {
            @Override
            protected void doInitPushClientChannel(SocketChannel ch) {
                //Inbound
                ch.pipeline().addLast("push-msg-request-client-handler", new PushMsgRequestClientHandler(msgType));
                ch.pipeline().addLast("push-msg-response-client-handler", new PushMsgResponseClientHandler());
            }
        };
    }

}
